Skip to content

Conversation

@mcndt
Copy link

@mcndt mcndt commented Oct 13, 2025

why

  1. In my organisation, we use Vertex AI for authenticated LLM calls using Google Cloud service accounts instead of the Gemini API keys.
  2. I also need control over the Vertex AI location being used for data residency guarantees.

what changed

I updated the typing of ClientOptions to support the full Google GenAI client constructor options, just like the Anthropic and OpenAI client options are already passed verbatim.

Because the Google GenAI client options don't have a baseUrl key, I also added explicit typing for the client options used for the ai-sdk model provider.

test plan

As this is only a typing change, I foresaw no immediate need for unit tests. Authentication with VertexAI is already tested as part of the GenAI client package.

@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2025

🦋 Changeset detected

Latest commit: a7ee673

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Summary

This PR updates the Google GenAI client to accept the full GoogleGenAIOptions type instead of a simplified ClientOptions interface, enabling Vertex AI authentication and region control.

Key Changes:

  • Updated ClientOptions type in types/model.ts to include GoogleGenAIClientOptions as a union member
  • Added intersection type with aisdk options (apiKey?, baseURL?) to support AI SDK language model providers
  • Modified GoogleClient.ts to import GoogleGenAIOptions directly from @google/genai and pass the full options object to the client constructor
  • Implementation now matches the pattern used by AnthropicClient and OpenAIClient, which pass their full client options verbatim

Potential Concern:
The intersection type on lines 48-57 of types/model.ts adds apiKey?: string and baseURL?: string to all client options. If GoogleGenAIOptions already defines these properties with different types, this could cause type conflicts. However, since the PR author states this is a typing-only change with no runtime impact, this suggests the properties are compatible.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - it's a type-only change that expands functionality without breaking existing code.
  • Score reflects the low-risk nature of the change (type definitions only), proper documentation via changeset, and consistent pattern matching with other client implementations. One point deducted due to potential type intersection conflicts with the added apiKey? and baseURL? properties in the union type - while likely compatible, this wasn't explicitly verified in the PR.
  • Pay attention to types/model.ts - verify that the intersection type with aisdk options doesn't conflict with existing GoogleGenAIOptions properties.

Important Files Changed

File Analysis

Filename Score Overview
types/model.ts 4/5 Updated ClientOptions type to include full GoogleGenAIClientOptions and added intersection with aisdk options (apiKey, baseURL). The intersection type may cause type conflicts if GoogleGenAIOptions already defines these properties.
lib/llm/GoogleClient.ts 5/5 Switched from local ClientOptions import to GoogleGenAIOptions directly from @google/genai. Changed constructor to pass full clientOptions to GoogleGenAI instead of just apiKey. Clean implementation that matches the pattern used by Anthropic and OpenAI clients.

Sequence Diagram

sequenceDiagram
    participant User
    participant Stagehand
    participant LLMProvider
    participant GoogleClient
    participant GoogleGenAI

    User->>Stagehand: Initialize with modelClientOptions
    Stagehand->>LLMProvider: getClient(modelName, clientOptions)
    LLMProvider->>GoogleClient: new GoogleClient({clientOptions})
    Note over GoogleClient: clientOptions now supports full GoogleGenAIOptions
    GoogleClient->>GoogleClient: Check for apiKey in clientOptions
    alt apiKey missing
        GoogleClient->>GoogleClient: loadApiKeyFromEnv()
    end
    GoogleClient->>GoogleGenAI: new GoogleGenAI(clientOptions)
    Note over GoogleGenAI: Full options passed (apiKey, location, project, etc.)
    GoogleGenAI-->>GoogleClient: client instance
    GoogleClient-->>LLMProvider: GoogleClient instance
    LLMProvider-->>Stagehand: LLMClient
    User->>Stagehand: createChatCompletion()
    Stagehand->>GoogleClient: createChatCompletion()
    GoogleClient->>GoogleGenAI: models.generateContent()
    GoogleGenAI-->>GoogleClient: response
    GoogleClient-->>Stagehand: LLMResponse
    Stagehand-->>User: result
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@mcndt mcndt force-pushed the feat/vertex-ai-support branch from 108b73a to ddd8a1a Compare November 3, 2025 19:22
@mcndt
Copy link
Author

mcndt commented Nov 4, 2025

If in the future you want to only support the AI SDK (basing this off #1129 (comment)), this is also possible, but typing will need to be expanded to allow passing other options than simply an API key and base URL:

Docs:

@mcndt mcndt force-pushed the feat/vertex-ai-support branch from 1968b25 to aaf728e Compare November 5, 2025 13:50
@mcndt mcndt force-pushed the feat/vertex-ai-support branch from aaf728e to a7ee673 Compare November 5, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant